
package com.zany.util.file;

import java.util.Properties;

import org.apache.log4j.Logger;


public class FileUploadPath {
    private static Logger logger = Logger.getLogger(FileUploadPath.class);
    
    public enum FileKey {
    	
    	BATCH_DOOR("BATCH.DOOR");
    	
    	
        private String key;

        private FileKey(String key) {
            this.key = key;
        }

        private String getKey() {
            return this.key;
        }
    }
    
    /**
     * 上传文件路径配置文件
     */
    private final static String UPLOAD_CONF = "/upload.properties";
    
    /**
     * 根目录路径
     */
    private final static String UPLOAD_ROOT_PATH = "BATCH.DOOR";
    
    /**
     * Resource for upload setting
     */
    private static Properties uploadProps = null;
    

    private FileUploadPath() {
    }
    
    /**
     * 得到资源文件的实例
     */
    private static void getInstance() {
        if(uploadProps == null) {
            try {
                uploadProps = new Properties();
                uploadProps.load(FileUploadPath.class.getResourceAsStream(UPLOAD_CONF));
            }
            catch (Exception e) {
                uploadProps = null;
                logger.error(e);
            }
        }
    }
    
    /**
     * 查询资源文件中上传文件的路径
     * @param fileKey   各功能KEY值
     * @return 上传路径（如：D:/WMS/documentfile/crm/specialvip/）
     */
    public static String getUploadFilePath(FileKey fileKey) {
        getInstance();       
        String propPath = uploadProps.getProperty(fileKey.getKey());
        return propPath;
    }
 
    /**
     * 查询上传文件的根目录
     * @return 根目录
     */
    public static String getUploadRootPath() {
        getInstance();
        String rootPath = uploadProps.getProperty(UPLOAD_ROOT_PATH);
        return rootPath;
    }
    
    /**
     * 取得web应用下的WEB-INF路径
     * 
     * @return WEB-INF路径
     */
    public static String getWebInfpath() {
        String filePath = FileUploadPath.class.getResource("").toString();
        filePath = filePath.substring(6, filePath.indexOf("classes"));
        return filePath;
    }
    
    public static void main(String[] args) {
        System.out.println(getWebInfpath());
    }
    
}
